<script setup lang="ts">
import { computed, inject } from "vue";
import type { FormDesignerComponents, FormItemPerm } from "../FormComponentMixin";
import { isReadonly } from "../FormItem";
const props = defineProps({
  type: {
    type: String,
    default: ""
  },
  mode: {
    type: String,
    default: "normal" //组件模式，free设计模式，normal 编辑模式, read 阅读模式，disable 禁用模式
  }
});

const _value = defineModel<string>();
const config = defineModel<FormDesignerComponents>("config");
const perm = inject<Array<FormItemPerm>>("perm");
const disabled = computed(() => {
  if (props.mode === "disable" && isReadonly(perm, config.value.code)) {
    return true;
  }
  return false;
});
</script>

<template>
  <el-radio-group v-if="config.props.expanding" v-model="_value" :disabled="disabled">
    <el-radio
      v-for="(op, i) in config.props.options"
      :key="i"
      :label="op.label"
      :value="op.value"
    />
  </el-radio-group>
  <el-select v-else v-model="_value" :disabled="disabled">
    <el-option
      v-for="(op, i) in config.props.options"
      :key="i"
      :label="op.label"
      :value="op.value"
    />
  </el-select>
</template>

<style scoped></style>
